load("//bazel:yr.bzl", "COPTS", "cc_strip")

cc_shared_library(
    name = "grpc_dynamic",
    shared_lib_name = "libgrpc_dynamic.so.1.65.4",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_protobuf//upb/wire",
    ],
)

cc_strip(
    name = "grpc_strip",
    srcs = [
        "//:grpc_dynamic",
    ],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "runtime_lib",
    srcs = glob([
        "src/libruntime/*.cpp",
        "src/libruntime/objectstore/*.cpp",
        "src/libruntime/objectstore/*.h",
        "src/libruntime/statestore/*.cpp",
        "src/libruntime/statestore/*.h",
        "src/libruntime/heterostore/*.h",
        "src/libruntime/heterostore/*.cpp",
        "src/libruntime/utils/*.cpp",
        "src/libruntime/utils/*.h",
        "src/libruntime/utils/crypto/*.cpp",
        "src/libruntime/utils/crypto/*.h",
        "src/libruntime/invokeadaptor/*.h",
        "src/libruntime/invokeadaptor/*.cpp",
        "src/libruntime/fsclient/*.cpp",
        "src/libruntime/fsclient/*.h",
        "src/libruntime/fsclient/grpc/*.cpp",
        "src/libruntime/fsclient/grpc/*.h",
        "src/libruntime/gwclient/http/*.h",
        "src/libruntime/gwclient/http/*.cpp",
        "src/libruntime/connect/*.h",
        "src/libruntime/connect/*.cpp",
        "src/libruntime/clientsmanager/*.h",
        "src/libruntime/clientsmanager/*.cpp",
        "src/libruntime/groupmanager/*.h",
        "src/libruntime/groupmanager/*.cpp",
        "src/dto/*.cpp",
        "src/libruntime/stacktrace/*.h",
        "src/libruntime/stacktrace/*.cpp",
        "src/libruntime/metricsadaptor/*.h",
        "src/libruntime/metricsadaptor/*.cpp",
        "src/libruntime/fmclient/*.cpp",
        "src/libruntime/fmclient/*.h",
        "src/libruntime/rgroupmanager/*.cpp",
        "src/libruntime/rgroupmanager/*.h",
    ]) + glob(
        ["src/libruntime/*.h"],
        exclude = [
            "src/libruntime/libruntime.h",
            "src/libruntime/libruntime_manager.h",
            "src/libruntime/err_type.h",
        ],
    ),
    hdrs = [
        "src/libruntime/err_type.h",
        "src/libruntime/libruntime.h",
        "src/libruntime/libruntime_manager.h",
    ] + glob([
        "src/dto/*.h",
    ]),
    copts = COPTS,
    linkopts = [
        "-L./external/boost/lib",
        "-lboost_atomic",
        "-lboost_fiber",
        "-lboost_context",
        "-lboost_filesystem",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
    deps = [
        "//src/libruntime/fsclient/protobuf:posix_cc_grpc",
        "//src/proto:libruntime_cc_proto",
        "//src/proto:socket_cc_proto",
        "//src/utility:yr_utils",
        "@boost",
        "@boringssl//:boringssl_sdk",
        "@com_github_grpc_grpc//:grpc++_public_hdrs",
        "@com_github_grpc_grpc//:grpc_core_credentials_header",
        "@datasystem_sdk//:lib_datasystem_sdk",
        "@metrics_sdk//:lib_metrics_sdk",
        "@msgpack",
        "@nlohmann_json",
        "@securec",
        "@com_googlesource_code_re2//:re2",
    ],
    alwayslink = True,
)

cc_library(
    name = "runtime_lib_hdrs",
    srcs = glob(
        [
            "src/libruntime/objectstore/*.h",
            "src/libruntime/statestore/*.h",
            "src/libruntime/heterostore/*.h",
            "src/libruntime/utils/*.h",
            "src/libruntime/utils/crypto/*.h",
            "src/libruntime/invokeadaptor/*.h",
            "src/libruntime/fsclient/*.h",
            "src/libruntime/fsclient/grpc/*.h",
            "src/libruntime/gwclient/http/*.h",
            "src/libruntime/connect/*.h",
            "src/libruntime/clientsmanager/*.h",
            "src/libruntime/groupmanager/*.h",
            "src/libruntime/stacktrace/*.h",
            "src/libruntime/metricsadaptor/*.h",
            "src/libruntime/fmclient/*.h",
            "src/libruntime/driverlog/*.h",
            "src/libruntime/rgroupmanager/*.h",
            "src/libruntime/*.h",
        ],
        exclude = [
            "src/libruntime/libruntime.h",
            "src/libruntime/libruntime_manager.h",
            "src/libruntime/err_type.h",
        ],
    ),
    hdrs = [
        "src/libruntime/err_type.h",
        "src/libruntime/libruntime.h",
        "src/libruntime/libruntime_manager.h",
    ] + glob([
        "src/dto/*.h",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        "//src/libruntime/fsclient/protobuf:posix_cc_grpc_hdrs",
        "//src/proto:libruntime_cc_proto_hdrs",
        "//src/proto:socket_cc_proto_hdrs",
        "//src/utility:yr_utils_hdrs",
        "@com_github_grpc_grpc//:grpc++_public_hdrs",
        "@com_github_grpc_grpc//:grpc_core_credentials_header",
        "@datasystem_sdk//:lib_datasystem_sdk",
        "@metrics_sdk//:lib_metrics_sdk",
        "@securec",
    ],
)